package vashion.azeroth.core.service.support;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import vashion.azeroth.core.personal.pojo.ConfigVip;

public class ConfigVipSupport {
	
	public ConfigVip calMemberVipLevel(Integer experience, List<ConfigVip> configVips) {
		Collections.sort(configVips);
		int i = 0;
		ConfigVip vip = null;
		for (ConfigVip configVip : configVips) {
			if(experience >= configVip.getExperienceValue()) {
				vip = configVip;
			} else {
				i++;
			}
			if(i > 0) {
				return null == vip?configVips.get(0):vip;
			}
		}
		
		return null == vip?configVips.get(0):vip;
	}
	
	public static void main(String[] args) {
		List<ConfigVip> configVips = new ArrayList<ConfigVip>();
		ConfigVip vip = new ConfigVip();
		vip.setExperienceValue(3000);
		vip.setVipLevel("level3");
		configVips.add(vip);
		
		ConfigVip vip1 = new ConfigVip();
		vip1.setExperienceValue(2000);
		vip1.setVipLevel("level2");
		configVips.add(vip1);
		
		ConfigVip vip2 = new ConfigVip();
		vip2.setExperienceValue(1000);
		vip2.setVipLevel("level1");
		configVips.add(vip2);
		
		ConfigVip vip3 = new ConfigVip();
		vip3.setExperienceValue(0);
		vip3.setVipLevel("level0");
		configVips.add(vip3);
		
		ConfigVipSupport vipService = new ConfigVipSupport();
		
//		System.out.println(vipService.calMemberVipLevel(1, configVips).getVipLevel());
		System.out.println(vipService.calMemberVipLevel(1000, configVips).getVipLevel());
//		System.out.println(vipService.calMemberVipLevel(1500, configVips).getVipLevel());
//		System.out.println(vipService.calMemberVipLevel(2500, configVips).getVipLevel());
//		System.out.println(vipService.calMemberVipLevel(3500, configVips).getVipLevel());
//		System.out.println(vipService.calMemberVipLevel(10000, configVips).getVipLevel());
	}
}
